﻿package ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;

import logicInterface.AdminLogicInterface;
import main.Main;
import vo.admin.AddUserPanelVO;
import vo.admin.ModifyUserPanelVO;

import components.MyButton;
import components.MyFrame;
import components.MyPanel;

public class ModifyUserPanel extends MyPanel{
	
	private MyButton logoutButton;
	private MyButton returnbackButton;
	
	JScrollPane modifypanelScrollPane;
	JLabel currentusernameLabel;
	JLabel pleasemodifyLabel;
	JLabel passwordmodifyLabel;
	JPasswordField passwordmodifyField;
	MyButton confirmmodifyButton;

	protected void initComponent() {
		String userName=null;
		AdminLogicInterface logic=Main.getLogic();
		try {
			userName=logic.getMpvo().getUserData()[logic.getMpvo().getSelectedRow()][0];
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		
		logoutButton = new MyButton("注销");
		returnbackButton = new MyButton("返回");
		logoutButton.setBounds(MyFrame.WIDTH-80,0, 80, 20);
		returnbackButton.setBounds(MyFrame.WIDTH-160,0, 80, 20);
		this.add(logoutButton);
		this.add(returnbackButton);
		
		modifypanelScrollPane = new JScrollPane(this);
	    modifypanelScrollPane.setBounds(300, 150, 500, 450);
	    modifypanelScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		pleasemodifyLabel = new JLabel("请填写以下信息:");
		currentusernameLabel = new JLabel("当前用户名:    "+userName);
		passwordmodifyLabel = new JLabel("密码:");
		passwordmodifyField = new JPasswordField();
		confirmmodifyButton = new MyButton("确认修改");
		pleasemodifyLabel.setBounds(10, 20, 120, 20);
		currentusernameLabel.setBounds(20, 60, 200, 20);
		passwordmodifyLabel.setBounds(20, 100, 80, 20);
	    passwordmodifyField.setBounds(100, 100, 150, 25);
		confirmmodifyButton.setBounds(350, 140, 100, 40);
		this.add(pleasemodifyLabel);
		this.add(currentusernameLabel);
		this.add(passwordmodifyLabel);
		this.add(passwordmodifyField);
		this.add(confirmmodifyButton);
		
		logoutButton.setButtonAction("logout");
		returnbackButton.setButtonAction("toMain");
		confirmmodifyButton.setButtonAction("modifyUser");
	}

	protected void updateVO() {
		ModifyUserPanelVO mupvo=null;
		try {
			mupvo = Main.getLogic().getMupvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		mupvo.setPassword(passwordmodifyField.getText());
		Main.getLogic().setMupvo(mupvo);
	}
}
